<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>大事件-首页</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/main.css">
</head>

<body>
    <div class="header">
        <a href="#" class="logo fl"><img src="images/logo.png" alt="logo"></a>
        <div class="search_form fl">
            <input type="text" class="search_txt" placeholder="黑洞照片">
            <button class="search_btn"><i class="fa fa-search"></i></button>
        </div>
        <div class="link_info fr">
            <a href="#"><i class="fa fa-angle-right"></i>&nbsp;&nbsp;网站地图</a><br>
            <a href="#"><i class="fa fa-angle-right"></i>&nbsp;&nbsp;招聘信息</a>
        </div>
    </div>

    <div class="menu_con">
        <div class="menu">
            <div class="menu_collapse fl">
                <a href="javascript:;" class="level_one"><i class="fa fa-list-ul"></i>全部分类</a>
                <ul class="level_two">
                    <li class="up"></li>
                    <li><a href="./list.html"></a></li>
                    <li><a href="./list.html"></a></li>
                    <li><a href="./list.html"></a></li>
                    <li><a href="./list.html"></a></li>
                    <li><a href="./list.html"></a></li>
                    <li><a href="./list.html"></a></li>
                </ul>
            </div>
            <ul class="left_menu fl">
                <li><a href="#"></a></li>
                <li><a href="#"></a></li>
                <li><a href="#"></a></li>
                <li><a href="#"></a></li>
                <li><a href="#"></a></li>
                <li><a href="#"></a></li>
            </ul>
            <ul class="right_menu fr">
                <li><a href="#">科技专题</a></li>
                <li><a href="#">财经专题</a></li>
            </ul>
        </div>
    </div>

    <div class="main_con clearfix">
        <div class="left_con">
            <ul class="focus_list">
                <li class="first">
                    <a href="#"><img src="" alt=""></a>
                    <p></p>
                </li>
                <li>
                    <a href="#"><img src="" alt=""></a>
                    <p></p>
                </li>
                <li>
                    <a href="#"><img src="" alt=""></a>
                    <p></p>
                </li>
                <li>
                    <a href="#"><img src="" alt=""></a>
                    <p></p>
                </li>
                <li>
                    <a href="#"><img src="" alt=""></a>
                    <p></p>
                </li>
            </ul>

            <div class="common_title">
                <h3><i class="fa fa-edit"></i> 最新资讯</h3>
                <a href="#" class="more"><i class="fa fa-angle-double-right"></i></a>
            </div>

            <div class="common_news">
                
                <div class="common_news_list">
                    <a href="#" class="list_pic"><img src="" alt=""></a>
                    <h4><a href="#"></a></h4>
                    <p>
                    </p>
                    <div class="new_info">
                        <span>标签：&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读( 5
                            )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( 10 )</span>
                        <b>发布于 </b>
                    </div>
                </div>

                <div class="common_news_list">
                    <a href="#" class="list_pic"><img src="" alt=""></a>
                    <h4><a href="#"></a></h4>
                    <p>
                    </p>
                    <div class="new_info">
                        <span>标签：&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读( 5
                            )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( 10 )</span>
                        <b>发布于 </b>
                    </div>
                </div>

                <div class="common_news_list">
                    <a href="#" class="list_pic"><img src="" alt=""></a>
                    <h4><a href="#"></a></h4>
                    <p>
                    </p>
                    <div class="new_info">
                        <span>标签：&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读( 5
                            )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( 10 )</span>
                        <b>发布于 </b>
                    </div>
                </div>

                <div class="common_news_list">
                    <a href="#" class="list_pic"><img src="" alt=""></a>
                    <h4><a href="#"></a></h4>
                    <p>
                    </p>
                    <div class="new_info">
                        <span>标签：&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读( 5
                            )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( 10 )</span>
                        <b>发布于 </b>
                    </div>
                </div>

                <div class="common_news_list">
                    <a href="#" class="list_pic"><img src="" alt=""></a>
                    <h4><a href="#"></a></h4>
                    <p>
                    </p>
                    <div class="new_info">
                        <span>标签：&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读( 5
                            )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( 10 )</span>
                        <b>发布于 </b>
                    </div>
                </div>
            </div>

        </div>
        <div class="right_con">
            <div class="common_wrap">
                <h3><i class="fa fa-bar-chart"></i> 一周热门排行</h3>
                <ul class="content_list hotrank_list">
                    <li><span class="first">1</span><a href="#"></a></li>
                    <li><span class="second">2</span><a href="#"></a></li>
                    <li><span class="third">3</span><a href="#"></a></li>
                    <li><span>4</span><a href="#"></a></li>
                    <li><span>5</span><a href="#"></a></li>
                    <li><span>6</span><a href="#"></a></li>
                    <li><span>7</span><a href="#"></a></li>
                </ul>
            </div>
            <div class="common_wrap">
                <h3><i class="fa fa-commenting-o"></i> 最新评论</h3>
                <ul class="content_list comment_list">
                    <li>
                        <span></span>
                        <b><em></em> </b>
                        <strong></strong>
                    </li>
                    <li>
                        <span></span>
                        <b><em></em> </b>
                        <strong></strong>
                    </li>
                    <li>
                        <span></span>
                        <b><em></em> </b>
                        <strong></strong>
                    </li>
                    <li>
                        <span></span>
                        <b><em></em> </b>
                        <strong></strong>
                    </li>
                   
                </ul>
            </div>
            <div class="common_wrap">
                <h3><i class="fa fa-bullseye"></i> 焦点关注</h3>
                <ul class="content_list guanzhu_list">
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                    <li><a href="#"></a></li>
                </ul>
            </div>
        </div>
    </div>

    <div class="footer clearfix">
        <div class="foot_link">
            <a href="#">关于我们</a>
            <span>|</span>
            <a href="#">联系我们</a>
            <span>|</span>
            <a href="#">招聘人才</a>
            <span>|</span>
            <a href="#">友情链接</a>
        </div>
        <p>CopyRight © 2019 深圳大事件信息技术股份有限公司 All Rights Reserved</p>
        <p>电话：0755-****888 粤ICP备*******8号</p>
    </div>

    <!-- 导入模板引擎js文件 -->
    <script src="./js/template-web.js"></script>
    <!-- 引入jq文件 -->
    <script src="./js/jquery-1.12.4.min.js"></script>
</body>

</html>
<!-- 热点图模板 -->
<script type="text/html" id="tpl-hotpic">
    {{each data}}
    {{if $index == 0}}
    <li class="first">
        {{else}}
    <li>
        {{/if}}
        <a href="./article.html?id={{$value.id}}"><img src="{{$value.cover}}" alt=""></a>
        <p>{{$value.title}}</p>
    </li>
    {{/each}}
</script>

<!-- 文章热门排行模板 -->
<script type="text/html" id="tpl-rank">
    {{each data}}
    <li>
        {{if $index == 0}}
            <span class="first">
        {{else if $index == 1}}
            <span class="second">
        {{else if $index == 2}}
            <span class="third">
        {{else}}
            <span>
        {{/if}}
            {{$index + 1}}</span><a href="./article.html?id={{$value.id}}">{{$value.title}}</a>
    </li>
    {{/each}}
</script>

<!-- 最新资讯模板 -->
<script type="text/html" id="tpl-latest">
    {{each data}}
    <div class="common_news_list">
        <a href="./article.html?id={{$value.id}}" class="list_pic"><img src="{{$value.cover}}" alt=""></a>
        <h4><a href="./article.html?id={{$value.id}}">{{$value.title}}</a></h4>
        <p>{{@ $value.intro}}</p>
        <div class="new_info">
            <span>标签：{{$value.category}}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<i class="fa fa-eye"></i>&nbsp;阅读(
                {{$value.read}}
                )&nbsp;&nbsp;&nbsp;<i class="fa fa-commenting"></i>&nbsp;评论( {{$value.comments}} )</span>
            <b>发布于 {{$value.date}}</b>
        </div>
    </div>
    {{/each}}
</script>

<!-- 最新评论模板 -->
<script type="text/html" id='tpl-latest-comment'>
    {{each data}}
    <li>
        <span>{{$value.author[0]}}</span>
        <b><em>{{$value.author}}</em> {{$value.date}} {{$value.time}} 说:</b>
        <strong>{{$value.intro}}</strong>
    </li>
    {{/each}}
</script>

<!-- 焦点关注模板 -->
<script type="text/html" id='tpl-attention'>
    {{each data}}
    <li><a href="./article.html?id='{{$value.id}}'">{{$value.intro}}</a></li>
    {{/each}}
</script>

<!-- 全部分类数据 -->
<script type="text/html" id='tpl-category'>
    {{each data}}
    <li><a href="./list.html?categoryId={{$value.id}}">{{$value.name}}</a></li>
    {{/each}}
</script>
<!-- <script type="text/html" id='tpl-category-right'>
    {{each data}}
    <li><a href="./list.html?id='{{$value.id}}">{{$value.name}}</a></li>
    {{/each}}
</script> -->


<script src="./js/http.js"></script>
<script>
    $(function () {
        // 0.封装函数 ：
        // url ：发起ajax的url地址
        // tplId ：模板结构的id值
        // className ：容器的类名，带有 .
        function loadData(arr) {
            $.ajax({
                type: 'get',
                url: arr.url,
                success: function (backData) {
                    // console.log(backData);
                    if (backData.code == 200) {
                        // 结合模板引擎生成标签结构
                        let htmlStr = template(arr.tplId, backData,arr.fun)
                        // if(arr.className.indexOf(',') > 0){
                        //     let class1 = arr.className.split(',')[0];
                        //     $(arr.className).html(htmlStr)

                        //     // 当前的容器需要添加一个头部li标签
                        //     let class2 = arr.className.split(',')[1];
                        //     $(arr.className).html('<li class="up"></li>' + htmlStr)
                        // 拓展 ：在形参加一个回调函数
                        if (arr.fun) {
                            arr.fun(arr.className, htmlStr);
                        } else {
                            $(arr.className).html(htmlStr)
                        }

                    }
                }
            })
        }

        let arr = [{
                url: BigNew.index_hotpic,
                tplId: 'tpl-hotpic',
                className: '.focus_list'
            },
            {
                url: BigNew.index_rank,
                tplId: 'tpl-rank',
                className: '.hotrank_list'
            },
            {
                url: BigNew.index_latest,
                tplId: 'tpl-latest',
                className: '.common_news'
            },
            {
                url: BigNew.index_latest_comment,
                tplId: 'tpl-latest-comment',
                className: '.comment_list'
            },
            {
                url: BigNew.index_attention,
                tplId: 'tpl-attention',
                className: '.guanzhu_list'
            },
            {
                url: BigNew.index_category,
                tplId: 'tpl-category',
                className: '.level_two,.left_menu',
                fun: function (className, htmlStr) {
                    let class1 = className.split(',')[0];
                    $(className).html(htmlStr)

                    // 当前的容器需要添加一个头部li标签
                    let class2 = className.split(',')[1];
                    $(className).html('<li class="up"></li>' + htmlStr)
                }
            }
        ]

        for (let i = 0; i < arr.length; i++) {
            loadData(arr[i])
        };


        // 7.给搜索按钮注册点击事件
        $('.search_btn').on('click', function () {
            // 获得搜索关键字
            let text = $('.search_txt').val().trim();
            if (text == '') {
                return;
            }

            // 携带搜索关键字跳转到文章列表页面
            window.location = './list.html?key='+text;
        })


        // 1.发起ajax请求，获得热点数据并且渲染页面结构
        // loadData(BigNew.index_hotpic,'tpl-hotpic','.focus_list')
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_hotpic,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code) {
        //             // 结合模板引擎生成标签结构
        //             let htmlStr = template('tpl-hotpic', backData)
        //             $('.focus_list').html(htmlStr)
        //         }
        //     }
        // })

        // 2.发起ajax请求，获得文章热门排行数据并且渲染页面结构
        // loadData(BigNew.index_rank,'tpl-rank','.hotrank_list')
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_rank,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code == 200) {
        //             let htmlStr = template('tpl-rank', backData);
        //             $('.hotrank_list').html(htmlStr)
        //         }
        //     }
        // })

        // 3.发起ajax请求，获得最新资讯数据并且渲染页面结构
        // loadData(BigNew.index_latest,'tpl-latest','.common_news')
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_latest,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code == 200) {
        //             let htmlStr = template('tpl-latest', backData)
        //             $('.common_news').html(htmlStr)
        //         }
        //     }
        // })

        // 4.发起ajax请求，获得最新评论数据并且渲染页面结构
        // loadData(BigNew.index_latest_comment,'tpl-latest-comment','.comment_list')
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_latest_comment,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code == 200) {
        //             let htmlStr = template('tpl-latest-comment', backData)
        //             $('.comment_list').html(htmlStr)
        //         }
        //     }
        // })

        // 5.发起ajax请求，获得焦点关注数据并且渲染页面结构
        // loadData(BigNew.index_attention,'tpl-attention','.guanzhu_list')
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_attention,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code == 200) {
        //             let htmlStr = template('tpl-attention', backData)
        //             $('.guanzhu_list').html(htmlStr)
        //         }
        //     }
        // })

        // 6.发起ajax请求，获得全部分类数据并且渲染页面结构
        // $.ajax({
        //     type: 'get',
        //     url: BigNew.index_category,
        //     success: function (backData) {
        //         // console.log(backData);
        //         if (backData.code == 200) {
        //             let htmlStr = template('tpl-category', backData)
        //             $('.level_two').html(htmlStr)

        //             let htmlStrRight = template('tpl-category-right', backData)
        //             $('.left_menu').html(htmlStr)
        //         }
        //     }
        // })

        // 7.给搜索按钮注册点击事件
        $('.search_btn').on('click', function () {
            // 获得搜索关键字
            let text = $('.search_txt').val().trim();
            if (text == '') {
                return;
            }

            // 携带搜索关键字跳转到文章列表页面
            window.location = './list.html?key='+text;
        })
    })
</script>